#include "playscene.h"
#include<QDebug>
#include<QMenuBar>
#include<QPainter>
#include"MyPushButton.h"
#include<QTimer>
#include<QLabel>
#include"mycoin.h"
//PlayScene::PlayScene(QWidget *parent) : QMainWindow(parent)
//{

//}
PlayScene::PlayScene(int levelNum)
{
    QString str=QString("进入了第%1关").arg(levelNum);
    qDebug()<<str;
    this->levelIndex=levelNum;


    //初始化游戏场景
    //设置固定大小
    this->setFixedSize(320,588);
    this->setWindowIcon(QPixmap(":/res/Coin0001.png"));
    //设置标题
    this->setWindowTitle("翻金币场景");

    //创建菜单栏
    QMenuBar * bar=menuBar();
    setMenuBar(bar);
    //创建开始菜单
    QMenu * startMenu=bar->addMenu("开始");
    //创建退出的菜单项
    QAction * quitAction=startMenu->addAction("退出");
    //点击退出 实现退出游戏
    connect(quitAction,&QAction::triggered,[=](){
        this->close();
    });

    //返回按钮
    MyPushButton * backBtn=new MyPushButton(":/res/BackButton.png",":/res/BackButtonSelected.png");
    backBtn->setParent(this);
    backBtn->move(this->width()-backBtn->width(),this->height()-backBtn->height());
    //点击返回
    connect(backBtn,&MyPushButton::clicked,[=](){
       qDebug()<<"翻金币的场景中点击了返回按钮";

       QTimer::singleShot(500,this,[=](){
           emit this->chooseSceneBack();
       });
    });


    //显示当前的关卡数
    QLabel * label=new QLabel;
    label->setParent(this);
    QFont font;
    font.setFamily("华文新魏");
    font.setPointSize(20);
    QString str1=QString("关卡：%1").arg(this->levelIndex);
    //将字体设置到标签控件中
    label->setFont(font);
    label->setText(str1);
    label->setGeometry(30,this->height()-100,120,50);



    //显示金币的背景图片
    for(int i=0;i<4;i++)
    {
        for(int j=0;j<4;j++)
        {
            //绘制背景图片
            QPixmap pix=QPixmap(":/res/BoardNode(1).png");
            QLabel * label =new QLabel;
            label->setGeometry(0,0,pix.width(),pix.height());
            label->setPixmap(pix);

            label->setParent(this);
            label->move(57+i*50,200+j*50);
            //创建金币
            MyCoin * coin=new MyCoin(":/res/Coin0001.png");
            coin->setParent(this);
            coin->move(59+i*50,204+j*50);

        }
    }


}
 void PlayScene::paintEvent(QPaintEvent *)
 {
     //创建背景
     QPainter painter(this);
     QPixmap pix;
     pix.load(":/res/secondbeijing.jpg");
     painter.drawPixmap(0,0,this->width(),this->height(),pix);
     //加载标题
     pix.load(":/res/Title.png");
     pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);
     painter.drawPixmap(10,30,pix.width(),pix.height(),pix);




 }
